helloprojectfandomcom_ja-20200214-history
モジュール:Sandbox/TimeTest
local p = {} itis = "Fight it out." D = {} J = {} T = {} function BirthdayInsert(Date, Japanese, Transliterated) table.insert(D, Date) table.insert(J, Japanese) table.insert(T, Transliterated) end BirthdayInsert('1984-07-17', '木村麻美', 'Kimura Asami') BirthdayInsert('2000-07-21', '田口夏実', 'Taguchi Natsumi') BirthdayInsert('1980-07-22', '北上アミ', 'Kitagami Ami') BirthdayInsert('1998-07-28', '岡村里星', 'Okamura Rise') BirthdayInsert('1989-07-23', '鍾安琪', 'Zhong An Qi') BirthdayInsert('1994-08-01', '和田彩花', 'Wada Ayaka') BirthdayInsert('1998-08-05', '鈴木香音', 'Suzuki Kanon') BirthdayInsert('1981-08-08', '飯田圭織', 'Iida Kaori') BirthdayInsert('1981-08-10', '安倍なつみ', 'Abe Natsumi') BirthdayInsert('1979-08-14', '三佳千夏', 'Miyoshi Chinatsu') BirthdayInsert('1992-08-25', '夏焼雅', 'Natsuyaki Miyabi') BirthdayInsert('1986-08-26', '川島幸', 'Kawashima Miyuki') BirthdayInsert('2001-08-26', '斎藤夏奈', 'Saito Kana') BirthdayInsert('1979-08-28', '前田有紀', 'Maeda Yuki') BirthdayInsert('1992-08-28', '趙國蓉', 'Zhao Guo Rong') BirthdayInsert('1998-08-28', '三瓶海南', 'Mikame Kana') BirthdayInsert('1999-08-29', '真城佳奈', 'Mashiro Kana') BirthdayInsert('2000-08-31', '井上ひかる', 'Inoue Hikaru') BirthdayInsert('1990-09-05', '阿部麻美', 'Abe Asami') BirthdayInsert('1983-09-06', 'ダニエル・デラウニー', 'Danielle Delaunay') BirthdayInsert('1996-09-06', '木沢留那', 'Kizawa Runa') BirthdayInsert('2000-09-06', '1', '100') BirthdayInsert('2000-09-07', '2', '101') BirthdayInsert('2000-09-08', '3', '102') BirthdayInsert('2000-09-09', '4', '103') BirthdayInsert('2000-09-10', '5', '104') BirthdayInsert('2000-09-11', '6', '105') BirthdayInsert('2000-09-12', '7', '106') function BirthdayCut(mmdd) --Find first entry that's on/after the given month/day wantedday = hyphentodayofyear('2000-' .. mmdd) i = 0 repeat i=i+1 thisday = hyphentodayofyear2000(Di) until thisday >= wantedday --We now want to move the first i entries in the three tables to the end to the end of those tables. for j=1, i, 1 do table.insert(D, D1) --Copy first value to new end entry... table.remove(D, 1) --Then remove the entry currently at first table.insert(J, J1) --Now do the same for J and T table.remove(J, 1) table.insert(T, T1) table.remove(T, 1) end end function BirthdayCut2(mmdd) --Find first entry that's on/after the given month/day wantedday = hyphentodayofyear('2000-' .. mmdd) i = 0 repeat i=i+1 thisday = hyphentodayofyear2000(Di) until thisday >= wantedday --We now want to move the first i entries in the three tables to temp tables. D2 = {} J2 = {} T2 = {} for j=1, i, 1 do table.insert(D2, D1) --Copy first value to new temp table... table.remove(D, 1) --Then remove the entry currently at first table.insert(J2, J1) --Now do the same for J and T table.remove(J, 1) table.insert(T2, T1) table.remove(T, 1) end --Now move values from temp tables to end of original tables. for j=1, i, 1 do D#D+1 = D2j J#J+1 = J2j T#T+1 = T2j end end function BirthdayCut3(mmdd) --Find first entry that's on/after the given month/day wantedday = hyphentodayofyear('2000-' .. mmdd) i = 0 repeat i=i+1 thisday = hyphentodayofyear2000(Di) until thisday >= wantedday --We now want to move the first i entries in the three tables to temp tables. D2 = {} J2 = {} T2 = {} for j=1, i, 1 do table.insert(D2, Dj) --Copy first value to new temp table... --table.remove(D, 1) --Then remove the entry currently at first table.insert(J2, Jj) --Now do the same for J and T --table.remove(J, 1) table.insert(T2, Tj) --table.remove(T, 1) end --Now shift values from original table without use of remove. for j=i+1, #D, 1 do Dj-i = Dj Jj-i = Jj Tj-i = Tj end --Now move values from temp tables to end of original tables. for j=1, i, 1 do D#D-i+j = D2j J#J-i+j = J2j T#T-i+j = T2j end end function BirthdayCut4(mmdd) --Find first entry that's on/after the given month/day wantedday = hyphentodayofyear('2000-' .. mmdd) i = 0 repeat i=i+1 thisday = hyphentodayofyear2000(Di) until thisday >= wantedday --We now want to copy the first i entries in the three tables to the table end. for j=1, i, 1 do table.insert(D, Dj) --Copy first value to new temp table... --table.remove(D, 1) --Then remove the entry currently at first table.insert(J, Jj) --Now do the same for J and T --table.remove(J, 1) table.insert(T, Tj) --table.remove(T, 1) end end function BirthdayCut3a(mmdd) --Find first entry that's on/after the given month/day --wantedday = hyphentodayofyear('2000-' .. mmdd) wantedday = mmdd i = 0 repeat i=i+1 --thisday = hyphentodayofyear2000(Di) thisday = string.sub( Di, 6, 10 ) --mw.log(thisday) until thisday >= wantedday --We now want to move the first i entries in the three tables to temp tables. D2 = {} J2 = {} T2 = {} for j=1, i, 1 do table.insert(D2, Dj) --Copy first value to new temp table... --table.remove(D, 1) --Then remove the entry currently at first table.insert(J2, Jj) --Now do the same for J and T --table.remove(J, 1) table.insert(T2, Tj) --table.remove(T, 1) end --Now shift values from original table without use of remove. for j=i+1, #D, 1 do Dj-i = Dj Jj-i = Jj Tj-i = Tj end --Now move values from temp tables to end of original tables. for j=1, i, 1 do D#D-i+j = D2j J#J-i+j = J2j T#T-i+j = T2j end end function p.test() return "Hello, world!" end function p.test2() return "2014-02-28 " .. (os.time{year=2014, month=02, day=28}) .. " 2014-02-29 " .. (os.time{year=2014, month=02, day=29}) .. " 2014-03-01 " .. (os.time{year=2014, month=03, day=01}) end function ostime (y,m,d) return os.time{year=y, month=m, day=d} end function ostimehyphen (yyyymmdd) _, _, y, m, d = string.find(yyyymmdd, "(%d%d%d%d)-(%d%d)-(%d%d)") return ostime(y,m,d) end function ostimehyphen2000 (yyyymmdd) _, _, y, m, d = string.find(yyyymmdd, "(%d%d%d%d)-(%d%d)-(%d%d)") return ostime(2000,m,d) end function ostimeNOWJST2000 () return ostimehyphen2000(os.date("%Y-%m-%d",os.time()+32400)) end function ostimeNEXJST2000(days) local num_days = days or 7 return ostimehyphen2000(os.date("%Y-%m-%d",os.time()+32400+(num_days-1)*86400)) end function hyphentodayofyear(yyyymmdd) return os.date("%j", ostimehyphen(yyyymmdd)) end function hyphentodayofyear2000(yyyymmdd) _, _, y, m, d = string.find(yyyymmdd, "(%d%d%d%d)-(%d%d)-(%d%d)") return os.date("%j", ostimehyphen('2000-' .. m .. '-' .. d)) end function WhereDayXStarts(mmdd) i = 0 repeat i=i+1 until string.sub( Di, 6, 10 ) >= mmdd return i end function WhereDayXEnds(mmdd) _, _, m, d = string.find(mmdd, "(%d%d)-(%d%d)") if d+1 < 10 then nextday = m .. "-0" .. d+1 --Needs zero padded else nextday = m .. "-" .. d+1 --Even if this date isnt' real, it should work as a point of comparison end if nextday "12-32" then return table.getn(D) -- As long as things are properly ordered, the table ends with the end of the year. else itbegins = WhereDayXStarts(nextday) ThenWhereDayXEnds = itbegins - 1 --Just before where the next day starts, see. if ThenWhereDayXEnds 0 then ThenWhereDayXEnds = table.getn(D) end --Again if the very beginning is "after", the end is... the end. return ThenWhereDayXEnds end end function p.test3() return "2014-02-28 " .. ostime(2014, 02, 28) .. " 2014-02-29 " .. ostime(2014, 02, 29) .. " 2014-03-01 " .. ostime(2014, 03, 01) end function TheScope () itis = "THIS BIG" end function p.test4() Thing = "The scope is " .. itis TheScope() Thing = Thing .. " The scope is " .. itis return Thing end function p.test5() return T1 .. " " .. T2 end function p.test6() return os.date("%c") end function p.test7() return "2014-02-28-0 " .. (os.time{year=2014, month=02, day=28, hour=0}) .. " 2014-02-28-9 " .. (os.time{year=2014, month=02, day=28, hour=9}) end function p.test8() return "NOW: " .. os.time() .. " JST: " .. os.time()+32400 end function p.test9() return "NOW: " .. os.date("%c") .. " JST: " .. os.date("%c", os.time()+32400) end function p.test10() return ":Easy\n:listening?" end function p.test11() return " NOWJST2000: " .. os.date("%Y-%m-%d",os.time()+32400) end function p.test11a() return " NOWJST2000a: " .. ostimehyphen(os.date("%Y-%m-%d",os.time()+32400)) end function p.test11b() return " NOWJST2000b: " .. ostimehyphen2000(os.date("%Y-%m-%d",os.time()+32400)) end function p.test12() return " Zukki: " .. ostimehyphen(D2) .. " " .. ostimehyphen2000(D2) end function p.test13() return ostimehyphen('2014-08-05') end function p.test13a() return ostimehyphen2000('2014-08-05') end function p.test14() yyyymmdd = "1990-07-17" _, _, y, m, d = string.find(yyyymmdd, "(%d%d%d%d)-(%d%d)-(%d%d)") return "Y " .. y .. " M " .. m .. " D " .. d end function p.testx2() date = "17/7/1990" _, _, d, m, y = string.find(date, "(%d+)/(%d+)/(%d+)") return y .. " " .. m .. " " .. d end function p.test15() return "ostimeNOWJST2000: " .. ostimeNOWJST2000() end function p.test16() return "ostimeNEXJST2000: " .. ostimeNEXJST2000() end --BirthdayCut3a('08-05') function p.upcoming(frame) --local num_days = frame.args.days or 7 --local num_min = frame.args.min or 2 local num_days = tonumber(frame.args.days or 7) local num_min = tonumber(frame.args.min or 2) local starting = frame.args.starting or os.date("%m-%d",os.time()+32400) --BirthdayCut3a(starting) --NOWJST2000 = ostimeNOWJST2000() NOWJST = starting --NEXJST2000 = ostimeNEXJST2000(num_days) --NEXJST = output = os.clock() .. "\n" .. "" counter = 0 first = 0 lastdate = 0 for i=1, table.getn(D), 1 do --output = output .. ":[.. T[i .. "]] (" .. Di .. ")" if ostimehyphen2000(Di) >= NOWJST2000 and ostimehyphen2000(Di) <= NEXJST2000 then output = output .. " It's both." if ostimehyphen2000(Di) ~= lastdate then if ostimehyphen2000(Di) NOWJST2000 then output = output .. " HAPPY BIRTHDAY" else output = output .. " COMING SOON" end end output = output .. ":[.. T[i .. "]] (" .. Di .. ")\n" lastdate = ostimehyphen2000(Di) counter = counter+1 if first 0 then first = i if ostimehyphen2000(Di+num_min-1) > NEXJST2000 then NEXJST2000 = ostimehyphen2000(Di+num_min-1) end --Minimum goes to this date, so make that date the finish date. end end end output = output .. "There were " .. counter .. ". " output = output .. "I wanted " .. num_min .. ". " if counter >= num_min then output = output .. "That's enough." else output = output .. "That's not enough." end return output .. " " .. os.clock() end function p.test17() return "NOW: " .. os.date("%c") .. " Different: " .. os.date("%j") end function p.test18() return "01-01: " .. hyphentodayofyear('2000-01-01') .. " 02-01: " .. hyphentodayofyear('2000-02-01') .. " 03-01: " .. hyphentodayofyear('2000-03-01') .. " 03-01: " .. hyphentodayofyear('2014-03-01') .. " 02-29: " .. hyphentodayofyear('2014-02-29') end function p.test18a() return "01-01: " .. hyphentodayofyear2000('2000-01-01') .. " 02-01: " .. hyphentodayofyear2000('2000-02-01') .. " 03-01: " .. hyphentodayofyear2000('2000-03-01') .. " 03-01: " .. hyphentodayofyear2000('2014-03-01') .. " 02-29: " .. hyphentodayofyear2000('2014-02-29') end function p.test19() return os.clock() end function p.test20() return BirthdayCut('08-05') end function p.test21() mmdd = "07-17" _, _, m, d = string.find(mmdd, "(%d%d)-(%d%d)") return "M " .. m .. " D " .. d end function p.test22() return "2013-12-31 " .. (os.time{year=2013, month=12, day=31}) .. " 2013-12-32 " .. (os.time{year=2013, month=12, day=32}) .. " 2014-01-01 " .. (os.time{year=2014, month=01, day=01}) end function p.test23() return "Where 12-28 starts: " .. WhereDayXStarts('12-28') .. " " .. TWhereDayXStarts('12-28') end function p.test24() return "Where 01-02 ends: " .. WhereDayXEnds('01-02') .. " " .. TWhereDayXEnds('01-02') end function p.test25() mmdd='08-07' i = 0 repeat i=i+1 until string.sub( Di, 6, 10 ) >= mmdd return string.sub( Di, 6, 10 ) .. ">=" .. mmdd end function p.test26() starting = '08-07' part1 = string.sub(starting,1,2) part2 = string.sub(starting,4,5) num_days = 7 return "P1: " .. part1 .. " P2: " .. part2 .. " End day: " .. os.date("%m-%d", os.time{year=2001, month=string.sub(starting,1,2), string.sub(starting,4,5)}+86400*num_days-1) end function p.test27() starting = '08-07' part1 = string.sub(starting,1,2) part2 = string.sub(starting,4,5) num_days = 7 return os.date("%m-%d", os.time{year=2001, month=string.sub(starting,1,2), day=string.sub(starting,4,5)}+86400*num_days-1) end function p.test28() starting = '08-07' part1 = string.sub(starting,1,2) part2 = string.sub(starting,4,5) num_days = 7 return os.date("%m-%d", os.time{year=2001, month=tonumber(string.sub(starting,1,2)), day=tonumber(string.sub(starting,4,5))}+86400*num_days-1) end function p.test29() mmdd = '01-02' _, _, m, d = string.find(mmdd, "(%d%d)-(%d%d)") nextday = m .. "-" .. d+1 return nextday end function p.upcoming2(frame) num_days = tonumber(frame.args.days or 7) num_min = tonumber(frame.args.min or 2) starting = frame.args.starting or os.date("%m-%d",os.time()+32400) ending = os.date("%m-%d", os.time{year=2001, month=string.sub(starting,1,2), day=string.sub(starting,4,5)}+86400*num_days-1) STARTBEGINS = WhereDayXStarts(starting) ENDENDS = WhereDayXEnds(ending) LISTEND = table.getn(D) output = "starting: " .. starting .. " ending: " .. ending .. " STARTBEGINS: " .. STARTBEGINS .. " ENDENDS: " .. ENDENDS .. " LISTEND: " .. LISTEND startread2 = 0 endread2 = 0 if ENDENDS>STARTBEGINS then if (ENDENDS-STARTBEGINS+1) >= num_min then --Is Y greater than X and Y-X>=Min? Fantastic! Read from spots X through Y. output = output .. " CASE 1 " startread1 = STARTBEGINS endread1 = ENDENDS startread2 = 0 elseif (LISTEND-STARTBEGINS+1) >= num_min then --Is Y greater than X, Y-X=Min? OK, find what date X+Min is, find where that date ends, call it Y. Read from spots X through Y. output = output .. " CASE 2 " ending = string.sub(DSTARTBEGINS+num_min-1, 6, 10 ) --mm-dd for minimum spot ENDENDS = WhereDayXEnds(ending) startread1 = STARTBEGINS endread1 = ENDENDS else --Need more to hit minimum, rest of list isn't enough. Need to check beginning of list for end of minimum and read those too. output = output .. " CASE 3 " ending = string.sub(Dnum_min-(LISTEND-STARTBEGINS+1), 6, 10 ) --mm-dd for minimum spot ENDENDS = WhereDayXEnds(ending) startread1 = STARTBEGINS endread1 = LISTEND startread2 = 1 endread2 = ENDENDS end else if (LISTEND-STARTBEGINS+ENDENDS) >= num_min then --Is Y less than X and (End-X+Y)>=Min? Read from spots X through End, then 1 through Y. output = output .. " CASE 4 " startread1 = STARTBEGINS endread1 = LISTEND startread2 = 1 endread2 = ENDENDS else --Is Y less than X, (End-X+Y)